<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>编辑信息</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="form-info">
            <div class="info-title">
                <span class="name">个人信息</span>
            </div>
            <form class="info-form">
                <div>
                    <input v-model="memberInfo.id" type="hidden">
                </div>
                <div class="input-row">
                    <label>姓名</label>
                    <input v-model="memberInfo.name" type="text" class="input-clear" placeholder="请输入姓名">
                </div>
                <div class="input-row single-radio">
                    <label class="radio-title">性别</label>
                    <div class="radio-list">
                        <div class="radio">
                            <input v-model="memberInfo.sex" id="item1" type="radio" name="sex" value="1" checked>
                            <label for="item1"></label>
                            <span>男</span>
                        </div>
                        <div class="radio">
                            <input v-model="memberInfo.sex" id="item2" type="radio" name="sex" value="2">
                            <label for="item2"></label>
                            <span>女</span>
                        </div>
                    </div>
                </div>

                <div class="input-row">
                    <label>手机号</label>
                    <input v-model="memberInfo.phoneNumber" type="text" class="input-clear"
                           placeholder="请输入手机号" readonly="true">
                    <i class="icon-rit-arrow" class="picktime" @click="changePhone"></i>
                </div>

                <div class="input-row">
                    <label>身份证号</label>
                    <input v-model="memberInfo.idCard" type="text" class="input-clear"
                           placeholder="请输入身份证号">
                </div>
                <div class="input-row">
                    <label>邮箱</label>
                    <input v-model="memberInfo.email" type="text" class="input-clear"
                           placeholder="请输入邮箱">
                </div>
                <div class="date">
                    <label>出生年月</label>
                    <i class="icon-date" id="change"></i>
                    <input v-model="memberInfo.birthday" type="text" class="picktime" readonly>
                </div>
            </form>
            <div class="box-button">
                <button @click="submitOrder()" type="button" class="btn order-btn">提交修改</button>
            </div>

            <!--原手机号码验证-->
            <div>
                <!--弹出手机号-->
                <el-dialog title="号码验证" :visible.sync="dialogFormVisible"
                           @close="handleClose">
                    <el-form :model="form">
                        <el-form-item label="验证码">
                            <el-col :span="12">
                                <el-input v-model="form.vCode"></el-input>
                            </el-col>
                            <el-col class="line" :span="2"></el-col>
                            <el-col :span="7">
                                <el-button id="validateCodeButton1" @click.prevent="sendVCode2old()"
                                           v-text="shows"></el-button>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="el-dialog--center">
                        <el-button @click="reset"> 取 消</el-button>
                        <el-button type="primary" @click="vidCode"> 确 定</el-button>
                    </div>
                </el-dialog>
            </div>


            <!--新手机号码绑定-->
            <div>
                <!--弹出手机号-->
                <el-dialog title="绑定新号码" :visible.sync="dialogFormVisible4"
                           @close="handleClose">
                    <el-form :model="form" :label-position="left">
                        <el-form-item label="手机号">
                            <el-col :span="17">
                                <el-input v-model="form.new"></el-input>
                            </el-col>
                        </el-form-item>

                        <el-form-item label="验证码">
                            <el-col :span="12">
                                <el-input v-model="form.vCode1"></el-input>
                            </el-col>
                            <el-col class="line" :span="2"></el-col>
                            <el-col :span="7">
                                <el-button id="validateCodeButton" @click.prevent="sendVCode2new()"
                                           v-text="shows"></el-button>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="el-dialog--center">
                        <el-button @click="reset"> 取 消</el-button>
                        <el-button type="primary" @click="vidCode1"> 修 改</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            dialogFormVisible: false,
            dialogFormVisible4: false,
            dialogFormVisiblePWD: true,
            memberInfo: {},
            form: {
                vCode: '',//验证码-old
                vCode1: '',//验证码-new
                old: '',//老号码
                new: '',//新号码
            },
            formLabelWidth: '120px',
            shows: '获取验证码',
            num: 10,
            pwd: null
        },
        methods: {
            //发送验证码给 老 号码
            sendVCode2old() {
                var tele = this.form.old;
                var eleId = 'validateCodeButton1';
                this.sendValidateCode(tele, eleId);
            },
            //发送验证码给 新 号码
            sendVCode2new() {
                var tele = this.form.new;
                var eleId = 'validateCodeButton';
                this.sendValidateCode(tele, eleId);
            },
            //发送验证码
            sendValidateCode(telephone, eleId) {
                //校验手机号
                if (!checkTelephone(telephone)) {
                    this.$message.error('请输入正确的手机号');
                    return false;
                }
                //倒计时效果
                this.loop(eleId);
                //发送验证码
                axios.post("/validateCode/send4Change.do?telephone=" + telephone).then((response) => {
                    if (!response.data.flag) {
                        //验证码发送失败
                        this.$message.error('验证码发送失败，请检查手机号输入是否正确');
                    }
                });
            },
            //倒计时效果
            loop(eleId) {
                this.num = 10;
                this.shows = this.num + "s后重新获取";
                var _this = this;
                clo = window.setInterval(function () {
                    //获取按钮
                    var element = document.getElementById(eleId);
                    element.disabled = true;
                    _this.num--;
                    if (_this.num > 0) {
                        _this.shows = _this.num + "s后重新获取";
                    } else {
                        clearInterval(clo);
                        element.disabled = false;
                        _this.shows = "重新获取";
                        _this.num = 10;
                    }
                }, 1000);
            },
            //修改号码弹窗
            changePhone() {
                this.dialogFormVisible = true;
                this.form.old = this.memberInfo.phoneNumber;
            },
            //重置计时器
            reset() {
                if (!typeof(clo) == undefined) {
                    clearInterval(clo);
                }
                this.shows = '获取验证码';
                this.num = 10;
                this.vCode = '';
                this.vCode1 = '';
                this.dialogFormVisible = false;
            },
            //弹窗关闭重置数据
            handleClose() {
                //alert("关闭了");
                this.reset();
                clearInterval(clo);
                this.form.new = '';
                this.form.vCode = '';
                this.form.vCode1 = ''
            },

            //提交验证码-old
            vidCode() {
                var _this = this;
                if (this.form.vCode == null || this.form.vCode == '') {
                    this.$message.error("请输入验证码");
                    return;
                } else {
                    //alert(this.form.vCode);
                    //ajax验证验证码
                    var data = {
                        telephone: this.form.old,
                        validateCode: this.form.vCode
                    }
                    axios.post("/login/checkOld.do", data).then((res) => {
                        //验证码正确
                        if (res.data.flag) {
                            _this.reset();
                            clearInterval(clo);
                            _this.dialogFormVisible4 = true;
                        } else {
                            //验证码错误
                            _this.$message.error('验证码错误');
                        }
                    });
                }
            },

            //提交验证码-new
            vidCode1() {
                var _this = this;
                if (this.form.vCode1 == null || this.form.vCode1 == '') {
                    this.$message.error("请输入验证码");
                    return;
                } else {
                    //alert(this.form.vCode);
                    //ajax验证验证码
                    var data = {
                        oldPhoneNum: this.memberInfo.phoneNumber,
                        newPhoneNum: this.form.new,
                        validateCode: this.form.vCode1
                    }
                    axios.post("/login/changePhoneNumber.do", data).then((res) => {
                        //验证码正确
                        if (res.data.flag) {
                            _this.reset();
                            _this.$message({
                                type: 'success',
                                message: '修改成功'
                            });
                            if (res.data.data != null) {
                                _this.memberInfo = res.data.data;
                            }
                            _this.dialogFormVisible4 = false;
                            //验证码错误
                        } else {
                            this.$message.error('验证码错误');
                        }
                    });

                }
            },
            //是否有登录
            isLogin() {
                axios.post("/login/isLogin.do").then((response) => {
                    if (response.data.flag) {
                        this.memberInfo = response.data.data;
                    } else {
                        window.location = 'http://localhost/pages/login.html';
                    }
                });
            },
            //提交表单
            submitOrder() {
                //验证身份证号
                if (!checkIdCard(this.memberInfo.idCard)) {
                    this.$message.error("请输入正确的身份证号码");
                    return;
                }
                //验证邮箱
                var reg = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
                var flag = reg.test(this.memberInfo.email)
                if (!flag) {
                    this.$message.error("请输入正确的邮箱");
                    return;
                }
                axios.post('/login/editMemberInfo.do', this.memberInfo).then((res) => {
                    if (res.data.flag) {
                        //修改成功
                        this.memberInfo = res.data.data;
                        this.$message({
                            type: 'success',
                            message: '更改信息成功!'
                        });
                    } else {
                        this.$message.error('更改信息失败!')
                    }
                })
            },


        },
        created() {
            this.isLogin();
        }
    });
</script>

<script>
    //日期控件
    var calendar = new datePicker();
    calendar.init({
        'trigger': '.picktime', /*按钮选择器，用于触发弹出插件*/
        'type': 'date', /*模式：date日期；datetime日期时间；time时间；ym年月；*/
        'minDate': '1880-01-01', /*最小日期*/
        'maxDate': getSpecifiedDate(new Date(), -1), /*最大日期*/
        'onSubmit': function () { /*确认时触发事件*/
            //var theSelectData = calendar.value;
        },
        'onClose': function () { /*取消时触发事件*/
        }
    });
</script>
</body>
</html>